package Command;

import java.util.ArrayList;
import java.util.List;

/**
 * @author duanzhizhou
 * @date 2024/11/4
 */
public class User {
    
    private List<Command> list = new ArrayList<>();
    
    public void compute(Command command) {
        command.Execute();
        list.add(command);
    }
    
    public void redo() {
        if (list.isEmpty()) {
            System.out.println("没有执行过操作");
            return;
        }
        Command command = list.get(list.size() - 1);
        compute(command);
    }
    
    public void undo() {
        if (list.isEmpty()) {
            System.out.println("已到达最开始");
            return;
        }
        Command command = list.remove(list.size() - 1);
        command.UnExecute();
    }
}
